#include <iostream>
using namespace std;

class Matrix
{
public:
    Matrix(float a, float b, float c, float d);
    Matrix(float a[]);

    Matrix& operator+(const Matrix &matrix);
    Matrix& operator*(const Matrix &matrix);
    Matrix& operator+=(const Matrix &matrix);

    float& operator()(int row, int column);
    float operator()(int row, int column) const;

    void print();

private:
    float _matrix[2][2];
};

Matrix::Matrix(float a, float b, float c, float d)
{
    _matrix[0][0] = a;
    _matrix[0][1] = b;
    _matrix[1][0] = c;
    _matrix[1][1] = d;
}

Matrix::Matrix(float a[4])
{
    _matrix[0][0] = a[0];
    _matrix[0][1] = a[1];
    _matrix[1][0] = a[2];
    _matrix[1][1] = a[3];
}

Matrix& Matrix::operator+(const Matrix &matrix)
{
    float a = _matrix[0][0] + matrix._matrix[0][0];
    float b = _matrix[0][1] + matrix._matrix[0][1];
    float c = _matrix[1][0] + matrix._matrix[1][0];
    float d = _matrix[1][1] + matrix._matrix[1][1];
    Matrix *temp = new Matrix(a,b,c,d);
    return *temp;
}

Matrix& Matrix::operator*(const Matrix &matrix)
{
    float a = _matrix[0][0] * matrix._matrix[0][0];
    float b = _matrix[0][1] * matrix._matrix[0][1];
    float c = _matrix[1][0] * matrix._matrix[1][0];
    float d = _matrix[1][1] * matrix._matrix[1][1];
    Matrix *temp = new Matrix(a,b,c,d);
    return *temp;
}

Matrix& Matrix::operator+=(const Matrix &matrix)
{
    _matrix[0][0] += matrix._matrix[0][0];
    _matrix[0][1] += matrix._matrix[0][1];
    _matrix[1][0] += matrix._matrix[1][0];
    _matrix[1][1] += matrix._matrix[1][1];
    return *this;
}

float& Matrix::operator()(int row, int column)
{
    return _matrix[row][column];
}

float Matrix::operator()(int row, int column) const
{
    return _matrix[row][column];
}

void Matrix::print()
{
    for (int ix = 0; ix < 2; ++ix)
    {
        for (int iy = 0; iy < 2; ++iy)
            cout << _matrix[ix][iy] << " ";
        cout << endl;
    }
}

int main(int argc, char *argv[])
{
    float f[4] = {5, 6, 7, 8};
    Matrix a(1,2,3,4);
    Matrix b(f);
    a.print();
    b.print();
    (a+b).print();
    (a*b).print();
    a += b;
    cout << a(1,1) << endl;

    return 0;
}
